import axios from "axios";
let requests = axios.create({
    baseURL: 'https://apipc-xiaotuxian-front.itheima.net',
    timeout: 5000
})
//请求拦截器
requests.interceptors.request.use(
    (config) => {
        let token = localStorage.getItem('TOKEN')
        if (token) {
            config.headers['Authorization'] = 'Bearer '+token
        }
        return config
    }
)
//响应拦截器
requests.interceptors.response.use(
    //成功
    (res) => {
        return res.data
    },
    //失败
    (err) => {
        return Promise.reject(new Error(err))
    }
)
export default requests